﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace VideoFlowTagger
{
	/// <summary>
	/// A NumberTotal object should be used to represent data like 13/22 
	/// (episode/disk number, total disks/episodes). 
	/// </summary>
    public struct NumberTotal
    {
        private int? number;
        private int? total;

        public NumberTotal(int number)
        {
            this.number = number;
            this.total = null;
        }

        public NumberTotal(int number, int total)
        {
            this.number = number;
            this.total = total;
        }

        public NumberTotal(string value)
        {
            int length = value.Length;
            int ofIndex = value.IndexOf(" of ");
            int totalIndex = length - ofIndex - 4;
            
            if (length == 2)
            {
                number = int.Parse(value.Substring(0, ofIndex));
                total = null;
            }
            else
            {
                number = int.Parse(value.Substring(0, ofIndex));
                total = int.Parse(value.Substring((ofIndex + 4), totalIndex));
            }
        }
		
		public int? GetNumber()
        {
            return this.number;
        }

        public int? GetTotal()
        {
            return this.total;
        }

        public override string ToString()
        {
            if (total == null)
                return number.ToString();
            else
                return number.ToString() + "/" + total.ToString();
        }
    }
}
